package com.cqh.servlet;

import com.cqh.bean.Grade;
import com.cqh.bean.Student;
import com.cqh.service.GradeService;
import com.cqh.service.StudentService;
import com.cqh.service.impl.GradeServiceImpl;
import com.cqh.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet(urlPatterns = "/Educational/student/deleteById")
public class DeleteByIdServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.接收参数
        String stuId = req.getParameter("stuId");
        //根据学生id删除学生信息
        StudentService studentService = new StudentServiceImpl();

        int i = studentService.delStu(stuId);
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter writer = resp.getWriter();
        if (i>0){
            writer.println("<script>alert('删除成功！');location.href='/Educational/student/getStudentList'</script>");
        }else {
            writer.println("<script>alert('删除失败！');location.href='/Educational/student/getStudentList'</script>");
        }

    }
}
